//
//  AppDelegate.m
//  DetailTest
//
//  Created by wp w on 12-6-19.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "AppDelegate.h"
#import "DLog.h"
#import "RootViewController.h"

@implementation AppDelegate

@synthesize window = _window;

- (void)dealloc
{
    [_window release];
    [super dealloc];
}

#pragma mark - lifecycle
/*
 程序启动流程：
 main
 -[AppDelegate application:didFinishLaunchingWithOptions:]//程序载入成功
 -[AppDelegate applicationDidBecomeActive:]//程序变为可见
 //按home键，变为后台程序（4.0）
 -[AppDelegate applicationWillResignActive:]//程序中断或者按home键 
 -[AppDelegate applicationDidEnterBackground:]//想要程序中断，变为不可见 
 //点击程序变为前台
 -[AppDelegate applicationWillEnterForeground:]//将要变为可见
 -[AppDelegate applicationDidBecomeActive:]//程序变为可见 
 */
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    DLogFun();
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    UIViewController* controller = [[[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil] autorelease];
    
    //设置statusbar
    [self StatusBarTest];
    
    //如果一个基于iPhone OS的设备在某个特定时间段中没有接收到触摸事件,就 会关闭屏幕,并禁用触摸传感器。以这种方式锁定屏幕是省电的重要方法。
    //将共享的UIApplication对象的idleTimerDisabled属性设置为YES, 就可以禁止屏幕锁定
    [UIApplication sharedApplication].idleTimerDisabled = YES;

    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    self.window.rootViewController = controller;
    [self.window makeKeyAndVisible];
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    DLogFun();
    //发生中断（active-->parse），此时会有一个选择对话框
    //系统检测到有电话、SMS信息、或者日历警告发生
    //系统显示一个带有事件信息的警告窗口。用户可以选择忽略或响应该事件
    //中断会导致应用程序暂 时失去控制权，如禁止将触摸事件发送给您的应用程序
    //如果控制权的丢失会影响程序的行为或导致不好的用户 体验,您就应该在委托方法中采取恰当的步骤进行规避
    //举例来说,如 果您的程序是个游戏,就应该暂停。您还应该禁用定时器、降低 OpenGL的帧率(如果正在使用OpenGL的话),通常还应该使应用程序 进行休眠状态。在这休眠状态下,您的应用程序继续运行,但是不应该 做任何重要的工作
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    DLogFun();
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    DLogFun();
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    DLogFun();
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    //用户忽略中断事件
    //您可以在这个方法中重新激活定时器、提高OpenGL的帧 率、以及将应用程序从休眠状态唤醒。对于处于暂停状态的游戏,您应 该考虑使它停在当时的状态上,等待用户做好重新玩的准备。举例来 说,您可以显示一个警告窗口,而窗口中带有重新开始的控件。
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    DLogFun();
    // 程序即将退出
}

#pragma mark - StatusBar
- (void)StatusBarTest
{
    //设置statusbar stytle
    [[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleDefault];
    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:YES];
    //隐藏
    [[UIApplication sharedApplication] setStatusBarHidden:YES];
}

//和其它应用程序进行通讯
//苹果内置支持http、mailto、tel、和sms这些URL模式,还支持基于 http的、指向Maps、YouTube、和iPod程序的URL。
//应用程序也可以自己注册定制的URL模式

@end
